
/*
	help() {  sed  -ne 's/\/\/\/usage://p' <(grep usage $1 ) }
*/

/*

	 	

\input texinfo   @c -*-texinfo-*-
@c %**start of header
@setfilename GetSF.info
@settitle HOW-TO GetSF
@c %**end of header

@setchapternewpage odd

@ifinfo
This is a short example of a usage.

Copyright 2012 I. Marfin

@end ifinfo

@titlepage
@sp 10
@comment The title is printed in a large font.
@center @titlefont{GetSF}

@c The following two commands start the copyright page.
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 2012 I. Marfin
@end titlepage

@node    Top,      HOW-TO start,         , (dir)
@comment node-name, next,          previous, up

@ifinfo
To get help on info window control, type '?'
@end ifinfo


@menu
* HOW-TO start::    The chapter about preparation of environment

* HOW-TO get SF::    The chapter about extracting SF. Examples

* Index::    The index of content

@end menu

@node   HOW-TO start, HOW-TO get SF, Top,      Top
@comment node-name,     next,          previous, up

@chapter HOW-TO start

@cindex HOW-TO start

Before get SF, you have to do several steps.


@enumerate

@item
cmsrel CMSSW_4_2_3
@item
cd CMSSW_4_2_3/src
@item
cmsenv
@item
#to setup CVSROOT

export CVSROOT=:gserver:marfin@@cmscvs.cern.ch:/cvs_server/repositories/CMSSW
/usr/kerberos/bin/kinit -5 marfin@@CERN.CH

@item
cvs co -r V01-03-11 RecoBTag/PerformanceDB
@item
cd RecoBTag/PerformanceDB/test
@item
tar -xf ../../../../../SF_BTAG.tgz .
@item
cd ../
@item
scramv1 b
@item
cmsRun DumpBtagTable_cfg.py >&| SF.log
@item

#get help on GetSF.C

grep usage GetSF.C

@item
# or use help() function,defined in GetSF.C: grep "help()" GetSF.C

help GetSF.C

@item
# or produce info 

makeinfo GetSF.C
info GetSF.C

@end enumerate

@cindex  Produce info help : makeinfo GetSF.C; info GetSF.C

@node   HOW-TO get SF,  Index,  HOW-TO start, Top
@comment node-name,    next,  previous,      up

@chapter  HOW-TO get SF

@enumerate

@item
@example
#get SF for Btagging at pT=40, eta =-0.3 
root -l -q 'GetSF.C(40,-0.3)'

@end example

@item

@example
#get SF for light-jets at pT=40,eta=-0.3 
root -l -q 'GetSF.C(40,-0.3,"SF.root","demo3","MISTAGTCHPT","BTAGLEFFCORR")'

@end example
@end enumerate


@node    Index,    ,   HOW-TO get SF, Top
@comment node-name,    next,  previous,      up
@unnumbered  Index

@printindex cp




@bye

*/

///usage: return SF for B-,Light- jets btagging from data
///usage: possible tagger names:
///usage: http://cmslxr.fnal.gov/lxr/source/RecoBTag/PerformanceDB/python/measure/Pool_mistag110711.py?v=CMSSW_6_0_0_pre1
///usage: http://cmslxr.fnal.gov/lxr/source/RecoBTag/PerformanceDB/python/measure/Pool_btag110711.py?v=CMSSW_6_0_0_pre1
///usage: (look at 'tag' options)
///usage: 
///usage: possible measure types:
///usage: grep "measureType" DumpBtagTable_cfg.py


///usage: makeinfo --no-headers GetSF.C

#include "TFile.h"
#include "TH2D.h"
#include "TString.h"

double GetSF(double _pT,double _Eta,TString fileName="SF.root",TString moduleName="demo3",TString taggerName="BTAGTCHPT", TString measureType ="BTAGBEFFCORR") ///usage:
{
double res=1e0;
TFile *_file = TFile::Open(fileName,"READ");
TH2 * _th2 = (TH2D*) _file->Get(moduleName+"/"+"h_"+taggerName+"_"+measureType);

if (!_th2) { cout<<"Something wrong"<<endl; return res;}
double _pTmin = _th2->GetXaxis()->GetXmin();
double _pTmax = _th2->GetXaxis()->GetXmax();
double _Etamin = _th2->GetYaxis()->GetXmin();
double _Etamax = _th2->GetYaxis()->GetXmax();

double pT = _pT;
double Eta = fabs(_Eta);

if (pT<=_pTmin) pT = _pTmin*1.001;
if (pT>=_pTmax) pT = _pTmax*(1.-0.001);
if (Eta<=_Etamin) Eta = _Etamin*1.001;
if (Eta>=_Etamax) Eta = _Etamax*(1.-0.001);

res = _th2->Interpolate(pT,Eta);

if (res<=0) res=1e0;

return res;
}
